/*
 * Copyright (C) 2010 Seapeak.Xu
 *
 * fostmq may be copied only under the terms of the GNU General
 * Public License V3, which may be found in the fostmq source kit.
 *
 * Created on: 2010-7-28
 * Author: Seapeak.Xu
 */

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <errno.h>
#include <string.h>
//#include <gc.h>

#include "fost_mem.h"
#include "fost_typedef.h"

void fost_mem_init(void)
{
//	GC_INIT();
	;
}

void *fost_malloc(size_t size)
{
	void *ptr =  malloc(size); 
	//GC_MALLOC(size);
	//malloc(size);
	if (NULL == ptr)
	{
		errno = 0 == errno ? ENOMEM : errno;
		return NULL;
	}
	return ptr;
}

void *fost_calloc(size_t numbs,size_t size)
{
	void *ptr = calloc(numbs,size);
        //fost_malloc(numbs * size); 
	//calloc(numbs,size);
	if(NULL == ptr)
	{
		errno = 0 == errno ? ENOMEM : errno;
		return NULL;
	}
	//memset(ptr, 0, numbs * size);
	return ptr;
}

void *fost_calloc1(size_t size)
{
	return fost_calloc(1,size);
}

char *fost_mallocs(size_t size)
{
	void *ptr = malloc(size);
	//GC_MALLOC_ATOMIC(size + 1);
	//malloc(size);
	if (NULL == ptr)
	{
		errno = 0 == errno ? ENOMEM : errno;
		return NULL;
	}
	return (char *) ptr;
}

char *fost_callocs(size_t numbs)
{
	return (char *) fost_calloc(numbs + 1,sizeof(char));
	
	/*  
	char *ptr = fost_mallocs((numbs) * sizeof(char));
	if (NULL == ptr)
	{
		errno = 0 == errno ? ENOMEM : errno;
		return NULL;
	}
	memset(ptr,0,(numbs + 1) * sizeof(char));
	return ptr;
	*/
}

void fost_free(void **ptr)
{
	if(NULL != *ptr)
	{
		free(*ptr);
		*ptr = NULL;
	}
}

